package com.ruoyi.system.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ExtHelper;
import com.ruoyi.common.utils.SpellUtils;
import com.ruoyi.common.utils.uuid.IdGeneratorSnowflake;
import com.ruoyi.system.domain.TrainingBase;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.TrainingBaseDeptMapper;
import com.ruoyi.system.domain.TrainingBaseDept;
import com.ruoyi.system.service.ITrainingBaseDeptService;

/**
 * 轮转科室信息Service业务层处理
 *
 * @author dp
 * @date 2023-11-27
 */
@Service
public class TrainingBaseDeptServiceImpl implements ITrainingBaseDeptService
{
    @Autowired
    private TrainingBaseDeptMapper trainingBaseDeptMapper;
    @Autowired
    IdGeneratorSnowflake idGeneratorSnowflake;

    /**
     * 查询轮转科室信息
     *
     * @param deptId 轮转科室信息主键
     * @return 轮转科室信息
     */
    @Override
    public TrainingBaseDept selectTrainingBaseDeptByDeptId(Long deptId)
    {
        return trainingBaseDeptMapper.selectTrainingBaseDeptByDeptId(deptId);
    }

    /**
     * 查询轮转科室信息列表
     *
     * @param trainingBaseDept 轮转科室信息
     * @return 轮转科室信息
     */
    @Override
    public List<TrainingBaseDept> selectTrainingBaseDeptList(TrainingBaseDept trainingBaseDept)
    {
        return trainingBaseDeptMapper.selectTrainingBaseDeptList(trainingBaseDept);
    }

    /**
     * 新增轮转科室信息
     *
     * @param trainingBaseDept 轮转科室信息
     * @return 结果
     */
    @Override
    public int insertTrainingBaseDept(TrainingBaseDept trainingBaseDept)
    {
        trainingBaseDept.setCreateTime(DateUtils.getNowDate());
        return trainingBaseDeptMapper.insertTrainingBaseDept(trainingBaseDept);
    }

    /**
     * 修改轮转科室信息
     *
     * @param trainingBaseDept 轮转科室信息
     * @return 结果
     */
    @Override
    public int updateTrainingBaseDept(TrainingBaseDept trainingBaseDept)
    {
        return trainingBaseDeptMapper.updateTrainingBaseDept(trainingBaseDept);
    }

    /**
     * 批量删除轮转科室信息
     *
     * @param deptIds 需要删除的轮转科室信息主键
     * @return 结果
     */
    @Override
    public int deleteTrainingBaseDeptByDeptIds(Long[] deptIds)
    {
        return trainingBaseDeptMapper.deleteTrainingBaseDeptByDeptIds(deptIds);
    }

    /**
     * 删除轮转科室信息信息
     *
     * @param deptId 轮转科室信息主键
     * @return 结果
     */
    @Override
    public int deleteTrainingBaseDeptByDeptId(Long deptId)
    {
        return trainingBaseDeptMapper.deleteTrainingBaseDeptByDeptId(deptId);
    }

    /**
     * 实体数据补全
     *
     * @param trainingBaseDept 实体
     * @param userId       用户id
     * @param crateType    创建类型 1：新增 2：修改
     */
    @Override
    public void completeData(TrainingBaseDept trainingBaseDept, Long userId, Integer crateType) {
        //主键
        if (trainingBaseDept.getDeptId() == null||"".equals(trainingBaseDept.getDeptId())) {
            trainingBaseDept.setDeptId(ExtHelper.toString(idGeneratorSnowflake.nextId()));
        }
        //编码
        if (trainingBaseDept.getDeptCode() == null||"".equals(trainingBaseDept.getDeptCode())) {
            trainingBaseDept.setDeptCode(SpellUtils.convertSpell(trainingBaseDept.getDeptName(), false));
        }
        //描述
        if (trainingBaseDept.getDeptDesc() == null) {
            trainingBaseDept.setDeptDesc("");
        }
        //是否有效
        if (trainingBaseDept.getIsValid() == null) {
            trainingBaseDept.setIsValid(1L);
        }
        //创建人、创建时间
        if (crateType == 1) {
            if (trainingBaseDept.getCreateBy() == null) {
                trainingBaseDept.setCreateBy(userId.toString());
            }
            if (trainingBaseDept.getCreateTime() == null) {
                trainingBaseDept.setCreateTime(DateUtils.getNowDate());
            }
        }
        //修改人
        if (trainingBaseDept.getModifyBy() == null) {
            trainingBaseDept.setModifyBy(userId);
        }
        //修改时间
        if (trainingBaseDept.getModifyTime() == null) {
            trainingBaseDept.setModifyTime(DateUtils.getNowDate());
        }
    }
}
